package com.smartEdu.handler.redis.pool;



import com.smartEdu.handler.redis.JedisPool;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPoolConfig;


public class JedisPoolApacheImpl implements IJedisPool {
	
	private JedisPool pool;

	public JedisPoolApacheImpl(String host, int port, String passowrd, int timeout, int maxActive) {

		JedisPoolConfig poolConfig = new JedisPoolConfig();
		// poolConfig.setMaxActive(maxActive);
		
		//最大并发
		poolConfig.setMaxTotal(maxActive);
		
		//控制一个pool最多有多少个状态为idle(空闲的)的jedis实例。
		poolConfig.setMaxIdle(maxActive);
		// poolConfig.setMinEvictableIdleTimeMillis(24 * 3600 * 1000);
		poolConfig.setMinEvictableIdleTimeMillis(-1);// 已建立的连接不回收，高并发时建立连接会很耗资源

		pool = new JedisPool(poolConfig, host, port, passowrd, timeout);
	}

	@Override
	public Jedis getResource() {
		return pool.getResource();
	}

	@Override
	public void returnBrokenResource(Jedis jedis) {
		pool.returnBrokenResource(jedis);
	}

	@Override
	public void returnResource(Jedis jedis) {
		pool.returnResource(jedis);
	}

	@Override
	public void destroy() {
		pool.destroy();
	}
}
